package com.ssy.lingxi.product.entity.commodity.member;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ssy.lingxi.product.entity.commodity.CommodityUnitPriceAndPic;
import com.ssy.lingxi.product.handler.converter.JpaJsonToMapConverter;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Map;

/**
 * 商品会员价格实体类
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/1/11
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_commodity_member_unitPrice")
public class CommodityMemberUnitPrice implements Serializable {
    private static final long serialVersionUID = -938409079229195700L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="commodity_member_unitPrice_seq")
    @SequenceGenerator(sequenceName="product_commodity_member_unitPrice_seq", name="commodity_member_unitPrice_seq",allocationSize = 1)
    private Long id;

    /**
     * 商品价格策略
     */
    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="commodityUnitPriceStrategyId",referencedColumnName = "id")
    private CommodityUnitPriceStrategy commodityUnitPriceStrategy;

    /**
     * 商品价格
     */
    @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="commodityUnitPriceId",referencedColumnName = "id")
    private CommodityUnitPriceAndPic commodityUnitPrice;

    /**
     * 商品单价
     */
    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition="jsonb", nullable = false)
    private Map<String,Double> unitPrice;

}
